#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "chr.h"

// #define CMD_IOC_MAGIC	'k'
// #define UNREVERSE _IO(CMD_IOC_MAGIC, 0)
// #define REVERSE	_IO(CMD_IOC_MAGIC, 1)


int main(int argc,char **argv)
{   
    if(argc <2)
    {
        printf("Usage:%s -w <string>\n",argv[0]);
        printf("Usage:%s -r \n",argv[0]);

        return -1;
    }
    
    int fd;
    char buf[1024];
    fd = open("/dev/mycdev_simple0",O_RDWR);
    if(fd < 0)
    {
        printf("can not open /dev/mycdev_simple0\n");
        return -1;
    }

//模式控制
    if(strcmp(argv[1],"uv")==0 )
    {
        ioctl(fd, UNREVERSE);
    }else
    {
        ioctl(fd, REVERSE);       
    }

    if(strcmp(argv[2],"-w")==0 )
    {
        write(fd, argv[3], strlen(argv[3]));
    }else
    {
        read(fd,buf,1024);
        buf[1023] = '\n';

        printf("APP get data %s\n",buf);
    }




    close(fd);
    
    return  0;
}
